package com.qf.service;

import com.github.pagehelper.PageHelper;
import com.qf.dao.ProfileDao;
import com.qf.pojo.Profile;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import java.util.ArrayList;
import java.util.List;

public class ProfileServiceImpl implements ProfileService {
    List<Profile> profileList = null;

    public ProfileDao profileDao;

    public void setProfileDao(ProfileDao profileDao) {
        this.profileDao = profileDao;
    }

    @Override
    public List<Profile> selectAll(int page_num,int page_size){
        profileList= new ArrayList<>();
        ApplicationContext applicationContext = new ClassPathXmlApplicationContext("spring-context.xml");
        ProfileDao bean = applicationContext.getBean(ProfileDao.class);
        PageHelper.startPage(page_num,page_size);
        List<Profile> profiles = bean.selectByPage();
//        List<Profile> profiles = profileDao.selectByPage();
        return profiles;
    }

    @Override
    public Profile selectById(int id) {
        Profile profile = profileDao.selectById(id);
        return profile;

    }

    @Override
    public void update(Profile profile) {
        profileDao.update(profile);
    }
}
